<template>
	<view class="page">
		<!-- 轮播图 -->
		<view class="bannerVue margin30">
			<u-swiper :list="banners" height="360" name="coverUrl"></u-swiper>
		</view>
		
		<!-- 声音创作/视频创作入口 -->
		<view class="section margin30 flex-between">
			<view class="li flex-column flex-center align-center" @click="$tools.navigate('./voice')">
				<u-icon name="mic" color="#fff" size="48"></u-icon>
				<u-gap height="10"></u-gap>
				<text>AI声音创作</text>
			</view>
			<view class="li flex-column flex-center align-center" @click="$tools.navigate('./video')">
				<u-icon name="camera-fill" color="#fff" size="48"></u-icon>
				<u-gap height="10"></u-gap>
				<text>AI视频创作</text>
			</view>
		</view>
		
		<!-- 学习教程 -->
		<view class="section margin50">
			<view class="flex-between align-center">
				<view class="title">学习教程</view>
				<text class="more" @click="$tools.route('./tutorial')">更多教程</text>
			</view>
			<view class="w100 margin20 flex-between flex-wrap">
				<view class="boxLi" v-for="(item, index) in tutorials" :key="index" style="margin-bottom: 0;">
					<view class="videoVue relative">
						<image :src="item.url+'?x-oss-process=video/snapshot,t_1,f_jpg,w_330,m_fast,ar_auto'" style="width: 330rpx;" mode='aspectFill'></image>
						<image src="../../static/play.png" style="width: 70rpx; height: 70rpx;z-index: 99;" class="absolute-auto" @click="$tools.router('../play', item.url)"></image>
					</view>
					<view style="line-height: 80rpx; text-align: center; color: #000; background: #fff; border-radius: 0 0 12rpx 12rpx;">{{item.title}}</view>
				</view>
			</view>
		</view>
		
		<!-- 用户案例 -->
		<view class="section margin50">
			<view class="flex-between align-center">
				<view class="title">用户案例</view>
				<text class="more" @click="$tools.route('./case')">更多案例</text>
			</view>
			<view class="w100 margin20 flex-between flex-wrap">
				<view class="boxLi" v-for="(item, index) in userCase" :key="index">
					<view class="videoVue relative">
						<image src="../../static/play.png" style="width: 70rpx; height: 70rpx;z-index: 99;" class="absolute-auto" @click="$tools.router('../play', item.videoUrl)"></image>
						<image :src="item.videoUrl+'?x-oss-process=video/snapshot,t_1,f_jpg,w_330,m_fast,ar_auto'" mode="aspectFill" style="width: 330rpx;"></image>
					</view>
					<view style="line-height: 80rpx; text-align: center; color: #000; background: #fff; border-radius: 0 0 12rpx 12rpx;">{{item.name}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				banners: [],
				userCase: [],
				tutorials: [],
				show: false,
			}
		},
		async onLoad() {
			await this.getBanners()
			await this.getVideoTutorial()
			await this.getUserCase()
		},

		methods: {
			// 获取轮播图
			async getBanners(){
				const res = await this.$request("/shuziren/carousels", {}, "GET")
				if(res.code===200) this.banners = res.data
			},
			
			// 获取全部视频教程
			async getVideoTutorial(){
				const res = await this.$request("/shuziren/videoTutorial", {}, "GET")
				if(res.code===200) this.tutorials = res.data.slice(0, 2)
			},
			
			// 获取用户案例
			async getUserCase(){
				const res = await this.$request("/shuziren/userVideo/public", {
					pageNum: 0,
					pageSize: 4
				}, "GET")
				if(res.code===200) this.userCase = res.data.content
			},
		}
	}
</script>

<style lang="less" scoped>
	/deep/.u-mode-center-box {
		background-color: transparent !important;
	}
	/deep/.u-drawer-center {
		background-color: transparent !important;
	}
	.bannerVue {
		width: 690rpx;
		height: 360rpx;
		background: #fff;
		border-radius: 12rpx;
		overflow: hidden;
	}
	.section {
		width: 690rpx;
		.li {
			width: 330rpx;
			height: 138rpx;
			background: #18AB4E;
			border-radius: 10rpx;
			text {
				font-size: 24rpx;
				color: #fff;
			}
		}
		.li:nth-child(2) {
			background: #2A6BEE;
		}
		.title {
			color: #000;
			font-weight: 600;
			font-size: 30rpx;
		}
		.more {
			color: #18AB4E;
			text-decoration: underline;
			font-size: 24rpx;
		}
		.boxLi {
			width: 330rpx;
			height: 600rpx;
			background: #f5f5f5;
			border-radius: 12rpx;
			margin-bottom: 30rpx;
			.videoVue {
				width: 330rpx;
				height: 520rpx;
				border-radius: 12rpx 12rpx 0 0;
				overflow: hidden;
			}
		}
	}
	.popVue {
		width: 520rpx;
	}
</style>
